package cycling.taxi.com.ui.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cycling.taxi.com.R;
import cycling.taxi.com.entity.Repair;
import cycling.taxi.com.entity.Tips;
import cycling.taxi.com.person.ExitApplication;
import cycling.taxi.com.utils.LogUtil;
import cycling.taxi.com.utils.Urls;

public class DispathItemActivity extends AppCompatActivity implements View.OnClickListener{
    @InjectView(R.id.tv_item_name)
    TextView nameTV;
    @InjectView(R.id.tv_item_price)
    TextView priceTV;
    @InjectView(R.id.tv_item_status)
    TextView tv_item_status;
    @InjectView(R.id.tv_item_createtime)
    TextView tv_item_createtime;
    @InjectView(R.id.tv_item_finshtime)
    TextView tv_item_finshtime;
    @InjectView(R.id.tv_item_dispatch)
    TextView tv_item_dispatch;
    @InjectView(R.id.tv_item_problem)
    TextView tv_item_problem;
    @InjectView(R.id.back)
    ImageView back;
    @InjectView(R.id.title_text)
    TextView title_text;
    private Repair repair;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dispath_item);
        ExitApplication.getInstance().addActivity(this);
        ButterKnife.inject(this);
        title_text.setText("派单详情");
        initData();
        setView();
    }
    public void initData(){
        repair=(Repair) getIntent().getSerializableExtra("Dispath");
        //LogUtil.e("Item:"+repair.toString());
        back.setOnClickListener(this);
    }
    public void setView(){
        if(repair.getUserTel()!=null) {
            nameTV.setText(repair.getUserTel());
        }
        if(repair.getImie()!=null){
            priceTV.setText(repair.getImie());
        }
        if(repair.getState()!=null) {
            if(repair.getState().equals("0")) {
                tv_item_status.setText("未完成");
            }else {
                tv_item_status.setText("已完成");
            }
        }
        if(repair.getCreateTime()!=null) {
            tv_item_createtime.setText(getStringDate(repair.getCreateTime()));
        }
        if(repair.getFinishTime()!=null){
            tv_item_finshtime.setText(getStringDate(repair.getFinishTime()));
        }
        if(repair.getDispatchAddress()!=null) {
            tv_item_dispatch.setText(repair.getName());
        }
        if(repair.getProblemDescription()!=null) {
            tv_item_problem.setText(repair.getProblemDescription());
        }
    }
    public static String getStringDate(Date date) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.back){
            finish();
        }
    }
}
